/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.rainbow.annotation;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;

/**
 *
 * @author hironaga
 */
public class AnnotationUtils {

    public static String getGetterMethodname(String fieldname){
        return "get" + Character.toUpperCase(
                                  fieldname.charAt(0)) + fieldname.substring(1);
    }

    public static String getSetterMethodname(String fieldname){
        return "set" + Character.toUpperCase(
                                  fieldname.charAt(0)) + fieldname.substring(1);
    }

    public static boolean isCollection(Class<?> cls){

        Class<?>[] ifs = cls.getInterfaces();
        if(ifs != null){
            for(int i=0; i<ifs.length; i++){
                if(ifs[i] == Collection.class){
                    return true;
                }
            }
        }
        return false;
    }

    public static Type getCollectionContentType(Field collection){
        ParameterizedType pType =(ParameterizedType)collection.getGenericType();
        return pType.getActualTypeArguments()[0];
    }
}
